package cn.didi.feidi.javabackend.server.waterdeliver.utils;

import java.util.Iterator;
import java.util.Map;

/**
 * Created by lindanpeng on 2017/7/17.
 */
public class UrlUtil {
    private static  String resolveVariables(Map<String, Object> params){
        if(params == null)
            return "";
        StringBuilder sb = new StringBuilder("?");
        Iterator<Map.Entry<String, Object>> iterator = params.entrySet().iterator();
        while(iterator.hasNext()){
            Map.Entry<String, Object> entry = iterator.next();
            sb.append(entry.getKey()+"="+entry.getValue()+"&");
        }
        int length = sb.toString().length();
        return sb.toString().substring(0, length - 1);
    }

    public static String getServerURL(String host, String port, String path, Map<String, Object> params){
        String result = "http://" + host + ":" + port + path + resolveVariables(params);
        System.out.println(result);
        return result;
    }

}
